package com.jie.controller;


import com.jie.annotation.Limit;
import com.jie.annotation.RedisCount;
import com.jie.constants.RedisCountConst;
import com.jie.constants.RedisLimitType;
import com.jie.dto.ActivityDTO;
import com.jie.dto.ActivityHotDTO;
import com.jie.dto.RedisCountDTO;
import com.jie.dto.UserDetailDTO;
import com.jie.response.RespBean;
import com.jie.service.IActivityService;
import com.jie.store.context.UploadStrategyContext;
import com.jie.utils.UserUtils;
import com.jie.vo.ActivityVo;
import com.jie.vo.ConditionVO;
import com.jie.vo.PageResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpSession;
import java.util.List;

/**
 * <p>
 * 热门活动表 前端控制器
 * </p>
 *
 * @author jie
 * @since 2024-04-24
 */
@RestController
@RequestMapping("/activity")
@Api(tags = "热门活动模块")
public class ActivityController {
    @Autowired
    private IActivityService iActivityService;
    @Limit(name = "Test Picture", prefix = "test", period = 10,capacity = 3,rate = 1,limitType = RedisLimitType.PICTURE)
    @ApiOperation("查看活动列表")
    @GetMapping("/get/activityPageList")
    public RespBean<?> getActivityPageList( ConditionVO conditionVO){
        PageResult<ActivityDTO> activityList=iActivityService.getActivityPageList(conditionVO);
        return  RespBean.success("热门活动列表",activityList);
    }
    @ApiOperation("根据活动id查看活动详细信息")
    @GetMapping("/get/activityById/{activityId}")
    public  RespBean<?> getActivityById(@PathVariable("activityId") Integer activityId){
        return RespBean.success("根据活动id查看活动详细信息",iActivityService.getActivityById(activityId));
    }
    @ApiOperation("查看热门活动列表按热度排行")
    @GetMapping("/get/activityHotPopularList")
    public RespBean<?> getActivityPopularList(){
        List<ActivityHotDTO> hotspotList=iActivityService.activityHotPopularList();
        return RespBean.success("查看热门活动列表按热度排行",hotspotList);
    }
    @ApiOperation("用户参加大众活动")
    @PostMapping("/join/activityInfo/{activityId}")
//    @Limit(key = "join_activityInfo", limitType = RedisLimitType.USER_ID,rate = 1,capacity = 10)
    @RedisCount(optSportType = RedisCountConst.ACTIVITY_USER_COUNT)
    public  RespBean<?> joinActivity(@PathVariable("activityId") Integer activityId){
        iActivityService.joinActivityInfo(activityId);
        return RespBean.success("用户参加活动成功",new RedisCountDTO(activityId));
    }
    @ApiOperation("用户参加秒杀活动 未完成")
    @PostMapping("/join/activityHotInfo/{activityId}")
    public  RespBean<?> activityHotInfo(@PathVariable("activityId") Integer activityId){
        //学习小红书
        return RespBean.success("用户参加活动成功",activityId);
    }
    @ApiOperation("用户取消活动")
    @PostMapping("/cancel/activityInfo/{activityId}")
    public  RespBean<?> cancelLockActivity(@PathVariable("activityId") Integer activityId){
        boolean flag=iActivityService.cancelLockActivityInfo(activityId);
        return RespBean.success("用户取消活动",flag);
    }
    @ApiOperation("管理员添加活动内容")
    @PostMapping("/admin/add/activityInfo")
    public  RespBean<?> addActivityInfo(@RequestBody ActivityVo activityVo){
        return RespBean.success("管理员添加活动内容成功",iActivityService.addActivityInfo(activityVo));
    }
    @ApiOperation("管理员修改活动内容")
    @PostMapping("/admin/update/activityInfo")
    public  RespBean<?> updateActivityInfo(@RequestBody ActivityVo activityVo){
        return RespBean.success("管理员添加活动内容成功",iActivityService.updateActivityInfo(activityVo));
    }
    @ApiOperation("管理员删除活动内容")
    @PostMapping("/admin/delete/activityInfo/{activityId}")
    public  RespBean<?> deleteActivityInfo(@PathVariable("activityId") Integer activityId){
        return RespBean.success("管理员添加活动内容成功",iActivityService.deleteActivityInfo(activityId));
    }

}

